<template>
  <div id="root">
    <div class="todo-container">
      <div class="todo-wrap">
        <Header-com :addTodo="addTodo"></Header-com>
        <List-com
          :TodoList="TodoList"
          :deleteTodo="deleteTodo"
          :checkedTodo="checkedTodo"
        ></List-com>
        <Footer-com
          :TodoList="TodoList"
          :isAllCheckedTodo="isAllCheckedTodo"
          :removerTod="removerTodo"
        ></Footer-com>
      </div>
    </div>
  </div>
</template>

<script>
// 引入School组件
import MyHeader from "./components/MyHeader";
import MyList from "./components/MyList";
import MyFooter from "./components/MyFooter";

export default {
  name: "App",
  components: {
    "Header-com": MyHeader,
    "List-com": MyList,
    "Footer-com": MyFooter,
  },
  data() {
    return {
      TodoList: [
        { id: "01", title: "吃饭", done: true },
        { id: "02", title: "睡觉", done: false },
        { id: "03", title: "打豆豆", done: true },
        { id: "04", title: "抽烟", done: false },
        { id: "05", title: "喝酒", done: true },
        { id: "06", title: "烫头发", done: false },
      ],
    };
  },
  methods: {
    addTodo(todo) {
      // console.log('我收到了')
      this.TodoList.unshift(todo);
    },
    deleteTodo(id) {
      // console.log('我收到了')
      this.TodoList = this.TodoList.filter((todo) => todo.id !== id);
    },
    checkedTodo(id) {
      // console.log('我收到了')
      this.TodoList.forEach((todo) => {
        if (todo.id === id) {
          todo.done = !todo.done;
        }
      });
    },
    isAllCheckedTodo(val) {
      // console.log("我收到了");
      this.TodoList.forEach((todo) => (todo.done = val));
    },
    removerTodo() {
      // console.log("我收到了");
      this.TodoList = this.TodoList.filter((todo) => !todo.done);
    },
  },
};
</script>

<style lang="less">
/*base*/
.btn {
  display: inline-block;
  padding: 4px 12px;
  margin-bottom: 0;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.05);
  border-radius: 4px;

  &:focus {
    outline: none;
  }
}

.btn-danger {
  color: #fff;
  background-color: #da4f49;
  border: 1px solid #bd362f;

  &:hover {
    background-color: #bd362f;
  }
}

.todo-container {
  width: 600px;
  margin: 0 auto;

  .todo-wrap {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
  }
}
</style>
